package com.burry.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import net.sf.json.JSONObject;
import applelew.util.Debug;

import com.burry.bo.JSONResult;
import com.burry.services.HoldService;

public class HoldAction extends BaseAction{
	
	private InputStream inputStream;
	private String goodId;
	private String colorId;
	private String upper;
	private String size;
	private String holder;
	
	public String getUpper() {
		return upper;
	}

	public void setUpper(String upper) {
		this.upper = upper;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getHolder() {
		return holder;
	}

	public void setHolder(String holder) {
		this.holder = holder;
	}

	public String getGoodId() {
		return goodId;
	}

	public void setGoodId(String goodId) {
		this.goodId = goodId;
	}

	public String getColorId() {
		return colorId;
	}

	public void setColorId(String colorId) {
		this.colorId = colorId;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getHolderInit(){
		HoldService hs = new HoldService();
		List holdList = hs.getAllHold(goodId, colorId);
		JSONResult json = new JSONResult(holdList);
		JSONObject jsonRet = JSONObject.fromObject(json);  
		String allSize = jsonRet.toString();

		try {
			setInputStream(new ByteArrayInputStream(allSize.getBytes("utf-8")));
		} catch (UnsupportedEncodingException e) {
			Debug.logError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public String updateHold(){
		HoldService hs = new HoldService();
		hs.updateHold(goodId, colorId, upper, size, holder);
		return SUCCESS;
	}

}
